package com.social.controller;

import com.social.pojo.Result;
import com.social.pojo.SysUser;
import com.social.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * @BelongsProject: social
 * @BelongsPackage: com.social.controller
 * @Author: zhm
 * @CreateTime: 2022-12-08  10:53
 * @Description: TODO
 * @Version: 1.0
 */
@Api("Register")
@RestController
@RequestMapping("")
public class RegisterController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 发送验证码
     * @param
     * @return
     */
    @ApiOperation("发送验证码")
    @PostMapping("code")
    public Result sendCode(@Valid @RequestParam("phone") String phone, HttpSession session) {
        System.out.println("phone" + phone);
        // 发送短信验证码并保存验证码
        return sysUserService.sendCode(phone, session);
    }

    /**
     * 用户注册
     * @param user
     * @param session
     * @return
     */
    @ApiOperation("用户注册")
    @PostMapping("register")
    public Result register(@Valid @RequestBody SysUser user, HttpSession session) {
        return sysUserService.register(user, session);
    }
}
